<div class="col-md-3" id="post_right_bar">

    <div id="post-actions" class="panel panel-default panel-lite">
        <div class="panel-body ">
            <div class="row">
                <% if @post.draft? && !@post.parent.present?  %>
                    <div class="col-md-12 input-submit"><%= f.submit "#{ (@post.new_record?) ? t('zerocms.admin.page_title.create') : t('zerocms.admin.button.update')}", class: "btn btn-success btn-lg btn-block" %></div>
                <% elsif @post.draft? && @post.parent.present? %>
                    <div class="col-md-12 input-submit"><%= f.submit "#{ t('zerocms.admin.button.recover') }", class: "btn btn-success btn-lg btn-block", onclick: "$('#post_status').val('#{@post.get_option('draft_status')}')" %></div>
                <% else  %>
                    <div class="col-md-12 input-submit"><%= f.submit "#{ (@post.new_record?) ? t('zerocms.admin.page_title.create') : t('zerocms.admin.page_title.update')}", class: "btn btn-success btn-lg btn-block" %></div>
                <% end  %>
            </div>
        </div>
        <div class="panel-footer">
            <div class="row">
                <div class="col-md-6 "><%= link_to t('zerocms.admin.button.move_trash'), {action: :trash, post_id: @post.id}, class: "text-center text-danger btn-xs btn" unless @post.new_record? %></div>
                <div class="col-md-6">
                    <% if @post.draft?  %>
                        <a class="btn btn-default btn-xs pull-right" href="#" data-type="pending" onclick="$('#form-post').submit(); return false;" style="<%= 'display: none' unless @post.pending? %>" ><%= t('zerocms.admin.post_type.save_pending')%> </a>
                        <a class="btn btn-default btn-xs pull-right" href="#" data-type="draft" onclick="App_post.save_draft(); return false;" style="<%= 'display: none' unless @post.draft? %>" ><%= t('zerocms.admin.post_type.save_draft')%></a>
                    <% else  %>
                        <a class="btn btn-default btn-xs pull-right" href="#" onclick="App_post.save_draft(); return false;" ><%= t('zerocms.admin.post_type.save_draft')%></a>
                    <% end  %>
                </div>

            </div>
        </div>
    </div>

    <div class="panel panel-default panel-lite">
        <div class="panel-heading">
            <h3 class="panel-title"><%= t('zerocms.admin.post_type.configuration')%></h3>
            <ul class="panel-controls">
                <li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
            </ul>
        </div>
        <div class="panel-body ">
            <div class="form-group">
                <label class=" control-label"><%= t('zerocms.admin.post_type.published')%></label>
                <select id="post_status" name="post[status]" class="form-control select">
                    <% if can? :publish_post, @post_type %>
                        <option class="" value="published" <%= (@post[:status] == "published") ? "selected": "" %> ><%= t('zerocms.admin.post_type.published')%></option>
                    <% end  %>
                    <option value="pending" <%= (@post[:status] == "pending") ? "selected": "" %>><%= t('zerocms.admin.table.pending')%></option>
                    <option value="draft" <%= (@post[:status] == "draft" || @post[:status] == "draft_child") ? "selected": "" %>><%= t('zerocms.admin.table.draft')%></option>
                </select>
            </div>
            <!-- templates -->
            <% if @post.manage_template?(@post_type) && (template_files = zerocms_get_list_template_files(@post_type)).present? %>
                <div class="form-group">
                    <label class="control-label"><%= t('zerocms.admin.post_type.template')%></label>
                    <%= select("meta", "template", template_files, { include_blank: true, selected: (params[:meta][:template] rescue false || @post.get_template(@post_type) ) }, {class: 'form-control'}) %>
                </div>
            <% end %>

            <!-- layouts -->
            <% if @post.manage_layout? && (layout_files = zerocms_get_list_layouts_files(@post_type)).present? %>
                <div class="form-group">
                    <label class="control-label"><%= t('zerocms.admin.post_type.layout')%></label>
                    <%= select("meta", "layout", layout_files, { include_blank: true, selected: (params[:meta][:layout] rescue false || @post.get_layout(@post_type) ) }, {class: 'form-control'}) %>
                </div>
            <% end %>

            <!-- page hierarchi -->
            <% if @post_type.manage_hierarchy? %>
                <div class="form-group">
                    <label class="control-label"><%= t('zerocms.admin.post_type.post_parent', layout: 'Parent Page')%></label>
                    <%= f.select :post_parent, zerocms_hierarchy_post_list(@post_type.posts.published.decorate.to_a).map{|p| [p.the_hierarchy_title, p.id] }, { include_blank: true, selected: (params[:post][:post_parent] rescue false || @post.post_parent ), disabled: (@post.full_children.zerocms_pluck(:id) << @post.id) }, {class: 'form-control'} %>
                </div>
            <% end %>

            <!-- has comments? -->
            <% if @post.manage_comments?(@post_type) %>
                <div class="form-group">
                    <label class="control-label"><%= check_box("meta", "has_comments", {checked: ((params[:meta][:has_comments] == '1' rescue false) || (@post.new_record? ? true : @post.get_meta('has_comments').to_s.zerocms_true?))  }) %> &nbsp; <%= t('zerocms.admin.post_type.permit_comments')%></label>
                </div>
            <% end %>
            <% if @post_type.get_option('has_featured', false) %>
                <div class="form-group">
                    <label class="control-label"><%= f.check_box :is_feature %> &nbsp; <%= t('zerocms.admin.post.is_featured', default: 'Is Featured?')%></label>
                </div>
            <% end %>
            <%= raw @post_form_extra_settings.join("") if @post_form_extra_settings.present? %>
        </div>
    </div>

    <% if @post_type.manage_categories? %>
        <div class="panel panel-default panel-lite">
            <div class="panel-heading">
                <h3 class="panel-title"><%= t('zerocms.admin.post_type.categories')%> <em class="text-danger">*</em></h3>
                <ul class="panel-controls">
                    <li><a id="post_add_new_category" data-reload-url="<%= list_zerocms_admin_post_type_categories_path(@post_type.id) %>" href="<%= zerocms_admin_post_type_categories_path(@post_type.id, zerocms_body_class: true) %>" title="<%= t("zerocms.admin.post.create_category", default: 'Create New Category') %>" class="panel-add-category"><span class="fa fa-plus"></span></a></li>
                    <li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
                </ul>
            </div>
            <div class="panel-body ">
                <div class="form-group list-categories">
                    <%= raw post_type_html_inputs(@post_type, "categories", "categories" , "checkbox" ,params[:categories] || (@post.new_record? ? [] : @post.categories.pluck("#{Zerocms::TermTaxonomy.table_name}.id")), "categorychecklist", true )%>
                </div>
            </div>
        </div>
    <% end %>
    <% if @post_type.manage_tags? %>
        <div class="panel panel-default panel-lite">
            <div class="panel-heading">
                <h3 class="panel-title"><%= t('zerocms.admin.post_type.tags')%></h3>
                <ul class="panel-controls">
                    <li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
                </ul>
            </div>
            <div class="panel-body ">
                <div class="form-group">
                    <input type="text" name="tags" class="tagsinput" value="<%= params[:tags] || (@post.post_tags.pluck("name").join(",") unless @post.new_record?) %>"/>
                </div>
            </div>
        </div>
    <% end %>

    <% if @post.manage_picture?(@post_type) %>
        <div class="panel panel-default panel-lite">
            <div class="panel-heading">
                <h3 class="panel-title"><%= t(@post_type.get_option('posts_feature_image_label', 'zerocms.admin.post_type.featured_image'), default: @post_type.get_option('posts_feature_image_label_default', 'Featured Image'))%> <%= "(#{@post_type.get_option('posts_image_dimension')})" if @post_type.get_option('posts_image_dimension').present? %> <%= '<em class="text-danger">*</em>'.html_safe if @post.is_required_picture? %></h3>
                <ul class="panel-controls">
                    <li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
                </ul>
            </div>
            <div class="panel-body ">
                <div class="form-group">
                    <div id="feature-image" class="gallery" style="display: <%= 'none' unless (params[:meta][:thumb] rescue false || @post.get_meta("thumb") ).present? %>">
                        <a class="gallery-item" style="width: 100%; padding: 0" href="#" title="Thumbnail" data-gallery="">
                            <div class="image">
                                <img src="<%= params[:meta][:thumb] rescue false || @post.get_meta("thumb", "") %>" class="img-rounded img-responsive" alt="Thumbnail">
                                <span class="gallery-item-remove btn btn-primary btn-xs"><i class="fa fa-times"></i></span>
                            </div>
                            <div class="meta text-center" style="margin-bottom: 16px">
                                <strong><%= (params[:meta][:thumb] || @post.get_meta("thumb")).split("/").last rescue "" %></strong>
                            </div>
                        </a>
                        <input data-error-place='#feature-image ~ .validation-errors:first' class="<%= 'required' if @post.is_required_picture? %>" name="meta[thumb]" type="hidden" value="<%= params[:meta][:thumb] rescue false || @post.get_meta("thumb", "") %>"/>
                    </div>
                    <!-- posts_thumb_versions ==> '200x200,400x450', posts_thumb_size ==> '100x100', posts_image_dimension ==> '1200x1200'-->
                    <a href="#" class="btn btn-default" onclick="zerocms_upload_feature_image({versions: '<%= @post_type.get_option('posts_thumb_versions') %>', thumb_size: '<%= @post_type.get_option('posts_thumb_size') %>', dimension: '<%= @post_type.get_option('posts_image_dimension') %>' }); return false;"><i class="fa fa-upload"></i> <%= t('zerocms.admin.post_type.upload_image', default: 'Upload Image')%></a>
                    <div class="validation-errors"></div>
                </div>
            </div>
        </div>
    <% end %>

    <%= _hook_args = {html: "", f: f, post: @post, post_type: @post_type}; hooks_run("post_form_sidebar_custom_html", _hook_args); raw(_hook_args[:html]); %>
</div>
